import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/colors.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/dialog/add_goods_info_dialog.dart';
import 'package:library_base/widget/dialog/as_goods_filter_dialog.dart';
import 'package:library_base/widget/dialog/avatar_select_dialog.dart';
import 'package:library_base/widget/dialog/batch_modification_single_head_dialog.dart';
import 'package:library_base/widget/dialog/commodity_info_entry%20_dialog.dart';
import 'package:library_base/widget/dialog/create_delivery_note_dialog.dart';
import 'package:library_base/widget/dialog/create_wms_dialog.dart';
import 'package:library_base/widget/dialog/create_wms_goods_dialog.dart';
import 'package:library_base/widget/dialog/create_wms_no_single_dialog.dart';
import 'package:library_base/widget/dialog/dynamic_bottom_option_dialog.dart';
import 'package:library_base/widget/dialog/fill_information_dialog.dart';
import 'package:library_base/widget/dialog/generate_sales_order_dialog.dart';
import 'package:library_base/widget/dialog/goods_list_dialog.dart';
import 'package:library_base/widget/dialog/incoming_orders_filter_dialog.dart';
import 'package:library_base/widget/dialog/loading_center_dialog.dart';
import 'package:library_base/widget/dialog/multiple_image_selection_dialog.dart';
import 'package:library_base/widget/dialog/order_screening_dialog.dart';
import 'package:library_base/widget/dialog/share_dialog.dart';
import 'package:library_base/widget/dialog/share_image_dialog.dart';
import 'package:library_base/widget/dialog/share_link_dialog.dart';
import 'package:library_base/utils/object_util.dart';
import 'package:library_base/route/routers.dart';
import 'package:library_base/widget/dialog/time_pick_and_consignee_dialog.dart';
import 'package:library_base/widget/dialog/time_pick_dialog.dart';

import 'bottom_option_dialog.dart';
import 'cupertino_alert_dialog.dart';

class DialogUtil {

  static void showCupertinoAlertDialog(BuildContext context,
      {String? title,
      String? content,
      String? cancel,
      String? confirm,
      Function()? cancelPressed,
      Function()? confirmPressed}) {
    List<Widget> actions = [];
    if (ObjectUtil.isNotEmpty(cancel)) {
      actions.add(CupertinoDialogAction(
          child: Text(cancel!, style: TextStyle(fontSize: 17, color: Colours.gray_500)),
          onPressed: cancelPressed));
    }

    if (ObjectUtil.isNotEmpty(confirm)) {
      actions.add(CupertinoDialogAction(
          child: Text(confirm!, style: TextStyle(fontSize: 17, color: Colours.app_main)),
          onPressed: confirmPressed));
    }

    showDialog(
        context: context,
        builder: (BuildContext context) {
          return CupertinoAlertDialog(
              title: ObjectUtil.isEmpty(title)
                  ? null
                  : Text(title!, style: TextStyle(fontSize: 17, color: Colours.gray_800)),
              content: ObjectUtil.isEmpty(content)
                  ? null
                  : Container(
                      margin: EdgeInsets.only(top: 10, bottom: 5),
                      child: Text(
                        content ?? '',
                        style: TextStyle(fontSize: 13, color: Colours.gray_500),
                        strutStyle: StrutStyle(forceStrutHeight: true, height: 1.2, leading: 0.5),
                      ),
                    ),
              actions: actions);
        });
  }

  static void showAvatarSelectDialog(BuildContext context,
      {bool crop = false, ValueChanged<String>? selectCallback, Function? viewCallback}) {
    showModalBottomSheet(
        context: context,
        backgroundColor: Colours.transparent,
        builder: (context) {
          return AvatarSelectDialog(
            crop: crop,
            selectCallback: selectCallback,
            viewCallback: viewCallback,
          );
        });
  }

  ///添加商品的Dialog
  static void showAddGoodsInfoDialog({Object? arguments}) {
    Get.dialog(const AddGoodsInfoDialog(), name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///创建销售单Dialog
  static void showGenerateSalesOrderDialog({Object? arguments}) {
    Get.dialog(const GenerateSalesOrderDialog(), arguments: arguments);
  }

  ///多图选择的Dialog
  static void showMultipleImageSelectionDialog({Object? arguments}) {
    Get.dialog(const MultipleImageSelectionDialog(),
        name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///添加商品的Dialog
  static void showSingleHeadDialog({Object? arguments}) {
    Get.dialog(const BatchModificationSingleHeadDialog(),
        name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///添加商品的Dialog
  static void showCreateDeliveryNoteDialog({Object? arguments}) {
    Get.dialog(const CreateDeliveryNoteDialog(),
        name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///显示加载中的弹窗
  static void showLoadingCenterDialog(BuildContext context,{Object? arguments,String? content}) {
    Get.dialog(LoadingCenterDialog(
      context,
      content: content ?? MultiLanguage.loading.tr,
      backgroundColor: ThemeUtil.getTheme().colorScheme.secondary,
      textColor: ThemeUtil.getTheme().normalTextColor(),
    ));
  }

  ///添加商品的Dialog
  static void showCreateWmsDialog({Object? arguments}) {
    Get.dialog(const CreateWmsDialog(),
        name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///添加商品的Dialog
  static void showFillInformationDialog({Object? arguments}) {
    Get.dialog(const FillInformationDialog(), arguments: arguments);
  }

  static void showCreateWmsGoodsDialog({Object? arguments}) {
    Get.dialog(const CreateWmsGoodsDialog(),
        name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  static void showCreateWmsNoSingleDialog({Object? arguments}) {
    Get.dialog(const CreateWmsNoSingleDialog(),
        name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///商品信息录入的dialog
  static void showCommodityInfoEntryDialog({Object? arguments}) {
    Get.dialog(const CommodityInfoEntryDialog(), arguments: arguments);
  }

  ///时间选择
  static void showTimePickDialog({Object? arguments}) {
    Get.dialog(const TimePickDialog(), name: Routers.addGoodsInfoDialog, arguments: arguments);
  }

  ///时间选择、收货人过滤
  static void showTimePickAndConsigneeDialog({Object? arguments}) {
    Get.dialog(const TimePickAndConsigneeDialog(),arguments: arguments);
  }

  ///按供应商、订单过滤
  static void showAsSupplierFilterDialog({Object? arguments}) {
    Get.dialog(const TimePickDialog(),arguments: arguments);
  }

  ///入库订单按时间、仓库过滤
  static void showIncomingOrdersFilterDialog({Object? arguments}) {
    Get.dialog(const IncomingOrdersFilterDialog(), arguments: arguments);
  }

  ///订单状态过滤
  static void showOrderScreeningDialog({Object? arguments}) {
    Get.dialog(const OrderScreeningDialog(), arguments: arguments);
  }

  ///底部 保存并提交 和 保存草稿 的弹窗
  static void showAsGoodsFilterDialog({Object? arguments}) {
    Get.dialog(const AsGoodsFilterDialog(), arguments: arguments);
  }

  ///底部 出现的功能选项选择
  static void showDynamicOptionDialog({Object? arguments}) {
    Get.bottomSheet(const DynamicOptionDialog(), settings: RouteSettings(arguments: arguments));
  }

  ///底部 保存并提交 和 保存草稿 的弹窗
  static void showBottomOptionDialog({Object? arguments}) {
    Get.bottomSheet(BottomOptionDialog(),
        isScrollControlled: true,
        settings: RouteSettings(arguments: arguments, name: Routers.addGoodsInfoDialog));
  }

  ///展示列表
  static void showBottomGoodsListDialog({Object? arguments}) {
    Get.bottomSheet(const GoodsListDialog(),
        isScrollControlled: true,
        settings: RouteSettings(arguments: arguments, name: Routers.addGoodsInfoDialog));
  }

  static void showShareDialog(BuildContext context, {List<Widget>? children}) {
    showModalBottomSheet(
        context: context,
        isScrollControlled: children != null,
        backgroundColor: Colours.transparent,
        builder: (context) {
          return ShareDialog(
            children: children,
          );
        });
  }

  static void showShareLinkDialog(
    BuildContext context, {
    required String url_share,
    String? title_share,
    String? summary_share,
    String? thumb_share,
  }) {
    showModalBottomSheet(
        context: context,
        isScrollControlled: false,
        backgroundColor: Colours.transparent,
        builder: (context) {
          return ShareLinkDialog(
            title_share: title_share,
            summary_share: summary_share,
            url_share: url_share,
            thumb_share: thumb_share,
          );
        });
  }

  static void showShareImageDialog(BuildContext context, {required String imgUrl}) {
    showModalBottomSheet(
        context: context,
        isScrollControlled: false,
        backgroundColor: Colours.transparent,
        builder: (context) {
          return ShareImageDialog(
            imgUrl: imgUrl,
          );
        });
  }
}
